// Thanks to https://github.com/nextmat/compass-960-plugin
$ninesixty-gutter-width: 20px !default;
$ninesixty-grid-width: 960px !default;
$ninesixty-columns: 12 !default;
$ninesixty-class-separator: "-" !default;

// Grid Container
@mixin grid-container {
    margin-left: auto;
    margin-right: auto;
    width: $ninesixty-grid-width;
}

// Grid Width
@mixin grid-width($n, $cols: $ninesixty-columns, $gutter-width: $ninesixty-gutter-width) {
    width: $ninesixty-grid-width / $cols * $n - $gutter-width;
}

// Grid Base
@mixin grid-unit-base($gutter-width: $ninesixty-gutter-width) {
    display: inline;
    float: left;
    margin: {
        left: $gutter-width / 2;
        right: $gutter-width / 2;
    };
}

// Grid
@mixin grid($n, $cols: $ninesixty-columns, $gutter-width: $ninesixty-gutter-width) {
    @include grid-unit-base($gutter-width);
    @include grid-width($n, $cols, $gutter-width);
}

// Alpha
@mixin alpha {
    margin-left: 0;
}

// Omeaga
@mixin omega {
    margin-right: 0;
}

// Grids
@mixin grids($cols: $ninesixty-columns, $gutter-width: $ninesixty-gutter-width) {
    #{enumerate(".grid", 1, $cols, $ninesixty-class-separator)} {
        @include grid-unit-base($gutter-width);
    }

    @for $n from 1 through $cols {
        .grid#{$ninesixty-class-separator}#{$n} {
            @include grid-width($n, $cols, $gutter-width);
        }
    }
}

// Grid Prefix
@mixin grid-prefix($n, $cols: $ninesixty-columns) {
    padding-left: $ninesixty-grid-width / $cols * $n;
}

// Grid Prefixes
@mixin grid-prefixes($cols: $ninesixty-columns) {
    @for $n from 1 through $cols - 1 {
        .prefix#{$ninesixty-class-separator}#{$n} {
            @include grid-prefix($n, $cols);
        }
    }
}

// Grid Suffix
@mixin grid-suffix($n, $cols: $ninesixty-columns) {
    padding-right: $ninesixty-grid-width / $cols * $n;
}

// Grid Suffixes
@mixin grid-suffixes($cols: $ninesixty-columns) {
    @for $n from 1 through $cols - 1 {
        .suffix#{$ninesixty-class-separator}#{$n} {
            @include grid-suffix($n, $cols);
        }
    }
}

// Grid Children
@mixin grid-children {
    .alpha {
        @include alpha;
    }

    .omega {
        @include omega;
    }
}

// Grid move base
@mixin grid-move-base {
    position: relative;
}

// Grid move push
@mixin grid-move-push($n, $cols: $ninesixty-columns) {
    left: $ninesixty-grid-width / $cols * $n;
}

// Grid move pull
@mixin grid-move-pull($n, $cols: $ninesixty-columns) {
    left: -($ninesixty-grid-width / $cols) * $n;
}

// Grid Push
@mixin grid-push($n, $cols: $ninesixty-columns) {
    @include grid-move-base;
    @include grid-move-push($n, $cols);
}

// Grid Pull
@mixin grid-pull($n, $cols: $ninesixty-columns) {
    @include grid-move-base;
    @include grid-move-pull($n, $cols);
}

// Grid Movements
@mixin grid-movements($cols: $ninesixty-columns) {
    #{enumerate(".push", 1, $cols - 1, $ninesixty-class-separator)},
    #{enumerate(".pull", 1, $cols - 1, $ninesixty-class-separator)} {
        @include grid-move-base;
    }

    @for $n from 1 through $cols - 1 {
        .push#{$ninesixty-class-separator}#{$n} {
            @include grid-move-push($n, $cols);
        }

        .pull#{$ninesixty-class-separator}#{$n} {
            @include grid-move-pull($n, $cols);
        }
    }
}

// Grid System
@mixin grid-system($cols: $ninesixty-columns) {
    @include grid-container;
    @include grids($cols);
    @include grid-prefixes($cols);
    @include grid-suffixes($cols);
    @include grid-children;
    @include grid-movements($cols);
}

// Grid System Complete
@mixin grid-system-complete($cols: $ninesixty-columns) {
    .container#{$ninesixty-class-separator}#{$cols} {
        @include grid-system($cols);
    }
}

// ***** rtPanel 960gs Grid Generator ***** //

// rtPanel Grid Generate.  ***** //
// Since we have renamed the classes in rtPanel. I have written the custom Grid Generator Code for rtPanel Grids.
@mixin rtp-grid-generator($cols: $ninesixty-columns) {
    .rtp-container-#{$cols} { @include grid-container; }

    /* Grid >> Global */
    #{enumerate(".rtp-grid", 1, $cols, $ninesixty-class-separator)} {
        @include grid-unit-base;
    }

    // Push and Pull Position
    #{enumerate(".rtp-push", 1, $cols - 1, $ninesixty-class-separator)},
    #{enumerate(".rtp-pull", 1, $cols - 1, $ninesixty-class-separator)} {
        @include grid-move-base;
    }

    /* Grid >> Children (Alpha ~ First, Omega ~ Last) */
    .rtp-alpha { @include alpha; }
    .rtp-omega { @include omega; }

    /* Grids */
    @for $i from 1 through $cols {
        .rtp-grid-#{$i} {
            @include grid-width($i, $cols);
        }
    }

    /* Extra Space */
    @for $i from 1 through $cols - 1 {
        // Prefix
        .rtp-prefix-#{$i} {
            @include grid-prefix($i, $cols);
        }

        // Suffix
        .rtp-suffix-#{$i} {
            @include grid-suffix($i, $cols);
        }
    }

    /* Push and Pull Space */
    @for $i from 1 through $cols {
        // Push
        .rtp-push-#{$i} {
            @if ($i != $cols ){
                @include grid-move-push($i, $cols);
            }
        }

        // Pull
        .rtp-pull-#{$i} {
            @if ($i != $cols ){
                @include grid-move-pull($i, $cols);
            }
        }
    }
}
// End of Grid Generator